<?php
/**
 * @package					Joomla.Site
 * @subpackage			mod_BP_googlemaps
 * @copyright				(C) 2012 Binary Pursuits All Rights Reserved
 * @license					
 */

// no direct access
defined('_JEXEC') or die;
$document =& JFactory::getDocument();
$document->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');

//var_dump ($map);
?>

<div class="bpgooglemaps<?php echo $moduleclass_sfx ?>"> 
	<div id="map_canvas" style="width: 600px; height: 600px; border: 1px #000000 solid;">
	</div>
</div>

<script type="text/javascript">

function initialize() {
	var myOptions = {
			zoom: <?php echo $map['zoom_level']; ?>,
			center: new google.maps.LatLng(<?php echo $map['latitude'] ?>, <?php echo $map['longitude'] ?>),
			disableDefaultUI: true,
			panControl: <?php echo $map['pan_control'] ?>,
			zoomControl: <?php echo $map['zoom_control'] ?>,
			mapTypeControl: <?php echo $map['map_control'] ?>,
			scaleControl: <?php echo $map['scale_control'] ?>,
			streetViewControl: <?php echo $map['street_control'] ?>,
			rotateControl: <?php echo $map['rotate_control'] ?>,
			overviewMapControl: <?php echo $map['overview_control'] ?>,
			mapTypeId: google.maps.MapTypeId.<?php echo $map['map_type'] ?>
  };
	console.log (myOptions);
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function loadScript() {
	var amp = "&";
	var script = document.createElement("script");
	var base_url = "http://maps.googleapis.com/maps/api/js?";
	var key = "key=" + "<?php echo $map['api_key']; ?>";
	var sensor = "sensor=false";
	var callback = "callback=initialize";
 
	script.type = "text/javascript";
	script.src = base_url + key + amp + sensor + amp + callback;
  
	document.body.appendChild(script);
}

$(window).load(function(){
	loadScript();
});

</script>